﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace View
{
    public partial class takeCash : Form
    {
        double szint;
        /// <summary>
        /// Amount download.
        /// </summary>
        public takeCash()
        {
            InitializeComponent();
            using (StreamReader sr = new StreamReader("amount.txt"))
            {
                szint = Convert.ToInt32(sr.ReadLine());

            }
        }
        /// <summary>
        /// exit.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button5_Click(object sender, EventArgs e)
        {

            this.Close();



        }
        /// <summary>
        /// Take cash.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            tbAmount.Text = "5";
        }

        private void button2_Click(object sender, EventArgs e)
        {
            tbAmount.Text = "10";
        }

        private void button3_Click(object sender, EventArgs e)
        {
            tbAmount.Text = "100";
        }
        /// <summary>
        /// Balance control, Cash recording.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button4_Click(object sender, EventArgs e)
        {
            try
            {
                for (int i = 0; i < tbAmount.Text.Length; i++)
                {
                    if (!((tbAmount.Text[i] >= '0') && (tbAmount.Text[i] <= '9')))
                    {
                        throw new ArgumentException();
                    }
                }


                if (szint < Convert.ToDouble(tbAmount.Text))
                {
                    MessageBox.Show("Not enough money! Please get your balance!");
                }
                else
                {
                    szint = szint - Convert.ToDouble(tbAmount.Text);
                    StreamWriter sw = new StreamWriter("amount.txt");
                    sw.WriteLine(szint);
                    sw.Close();
                    MessageBox.Show("Ready! Please take your Money!");
                }



            }
            catch (ArgumentException)
            {
                MessageBox.Show("Invalid character");
            }
            catch
            {
                MessageBox.Show("Hiba");
            }
        }
    }
}
